package com.ruoyi.web.controller.fx;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.fx.FxBanner;
import com.ruoyi.system.service.fx.IFxBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * banner图片Controller
 *
 * @author ruoyi
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/fx/banner")
public class FxBannerController extends BaseController {
    @Autowired
    private IFxBannerService fxBannerService;

    /**
     * 查询banner图片列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FxBanner fxBanner) {
        startPage();
        List<FxBanner> list = fxBannerService.selectFxBannerList(fxBanner);
        return getDataTable(list);
    }

    /**
     * 导出banner图片列表
     */
    @Log(title = "banner图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FxBanner fxBanner) {
        List<FxBanner> list = fxBannerService.selectFxBannerList(fxBanner);
        ExcelUtil<FxBanner> util = new ExcelUtil<FxBanner>(FxBanner.class);
        util.exportExcel(response, list, "banner图片数据");
    }

    /**
     * 获取banner图片详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(fxBannerService.selectFxBannerById(id));
    }

    /**
     * 新增banner图片
     */
    @Log(title = "banner图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FxBanner fxBanner) {
        return toAjax(fxBannerService.insertFxBanner(fxBanner));
    }

    /**
     * 修改banner图片
     */
    @Log(title = "banner图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FxBanner fxBanner) {
        return toAjax(fxBannerService.updateFxBanner(fxBanner));
    }

    /**
     * 删除banner图片
     */
    @Log(title = "banner图片", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fxBannerService.deleteFxBannerByIds(ids));
    }
}
